package mt.omid.dimomuth;


import java.util.Vector;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;


/**
 * This is supplementary class to manage Processes.
 * 
 * @author Omid
 * 
 */

public class ProcessManager
{

    private Vector<Process>	  readyList;
    private ScheduledExecutorService scheduler;
    private int		      pNumm = 0;


    public ProcessManager()
    {
	readyList = new Vector<Process>();
    }

    public void addProcess( Process p )
    {
	readyList.add( p );
	pNumm++;
    }

    public void startAll()
    {
	scheduler = Executors.newScheduledThreadPool( pNumm );
	for( Process p : readyList )
	{
	    scheduler.scheduleWithFixedDelay( p, 0, 60, TimeUnit.SECONDS );
	}
    }

    public void shutdownAll()
    {
	scheduler.shutdown();

	for( Process p : readyList )
	{
	    p.shutdown();
	}

	scheduler.shutdownNow();
    }
}
